//get fraction of movers in each state
import delimited "$dir/Model/Simulated_data/simulated_data_base.csv", clear

//rename
ren v1 state_born
ren v2 state_move
ren v14 weight
gen count = 1
keep state* count weight
keep if state_move!=state_born
collapse (sum) count [w=weight], by(state_move)
egen grandcount = total(count)
gen frac = count/grandcount
keep frac state_move
gen id = _n
tempfile migin_simul
save `migin_simul'

import delimited "$dir/Model/moments/state_inflow_rates.csv", clear
gen id = _n

merge 1:1 id using `migin_simul', keep(match) nogen
corr v1 frac //
su v1 frac
ren state_move statefips
merge 1:1 statefips using "$data/Crosswalks/state_fips_crosswalk", keep(match) nogen



maptile v1, geo(state)  spopt(mos(thick)legenda(off)) legdecimals(3) cutv(0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.08 0.10) rev
graph export "$output/fig5_receive_standard.png", replace 

maptile frac, geo(state)  spopt(mos(thick)) legdecimals(3) cutv(0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.08 0.10) rev
graph export "$output/fig5_receive_standard_simul.png", replace 

